<?php
class version extends Model
{
	public function addVersion($platformCode,$versionNum,$versionDesc,$publishFlag,$publishTime,$upgradeUrl)
	{
		$sql = "INSERT INTO `reporter_assistant`.`version` (`version_id`, `code_platform`, `version_num`, `version_desc`, `flag_publish`, `publish_time`, `upgrade_url`) 
				VALUES 
				(NULL, '".$platformCode."', '".$versionNum."', '".$versionDesc."', '".$publishFlag."', '".$publishTime."', '".$upgradeUrl."');";
		return $this->insert($sql);
	}
	public function modifyVersion($id,$platformCode,$versionNum,$versionDesc,$publishFlag,$publishTime,$upgradeUrl)
	{
		$sql = "UPDATE `reporter_assistant`.`version` 
				SET 
				`code_platform` = '".$platformCode."', 
				`version_num` = '".$versionNum."', 
				`version_desc` = '".$versionDesc."', 
				`flag_publish` = '".$publishFlag."', 
				`publish_time` = '".$publishTime."', 
				`upgrade_url` = '".$upgradeUrl."' 
				WHERE `version`.`version_id` = '".$id."';";
		return $this->update($sql);
	}
	public function getLastVersion($platformName,$numVersion)
	{
		$sql = "SELECT `version`.* FROM `version` LEFT JOIN `platform` ON `version`.`code_platform` = `platform`.`code_platform`
				WHERE `platform`.`platform_name`='".$platformName."' AND `version`.`version_num` > '".$numVersion."' AND `version`.`flag_publish`=1
				ORDER BY `version`.`version_num` DESC";
		//echo $sql;
		return $this->fetchAll($sql);
	}
}